<template>
  <ul class="tabs">
    <li
      class="switch-item"
      v-for="(item, index) in navList"
      :key="index"
      :class="{'active' : currentIndex === index}"
      @click="switchItem({ item, index })"
    >
      <span>
        <panda-icon v-if="index === 0" class="icon"></panda-icon>
        <a-icon v-else :type="iconList[index % 16]" class="icon"></a-icon>
        {{ item }}
      </span>
    </li>
  </ul>
</template>
<script>

const PandaSvg = {
  template: `
    <svg viewBox="0 0 1024 1024" width="1em" height="1em" fill="currentColor">
      <path d="M99.096 315.634s-82.58-64.032-82.58-132.13c0-66.064 33.032-165.162 148.646-148.646 83.37 11.91 99.096 165.162 99.096 165.162l-165.162 115.614zM924.906 315.634s82.58-64.032 82.58-132.13c0-66.064-33.032-165.162-148.646-148.646-83.37 11.91-99.096 165.162-99.096 165.162l165.162 115.614z" fill="#6B676E" p-id="1143" />
      <path d="M1024 561.548c0 264.526-229.23 429.42-512.002 429.42S0 826.076 0 561.548 283.96 66.064 512.002 66.064 1024 297.022 1024 561.548z" fill="#FFEBD2" p-id="1144" />
      <path d="M330.324 842.126c0 82.096 81.34 148.646 181.678 148.646s181.678-66.55 181.678-148.646H330.324z" fill="#E9D7C3" p-id="1145" />
      <path d="M644.13 611.098C594.582 528.516 561.55 512 512.002 512c-49.548 0-82.58 16.516-132.13 99.096-42.488 70.814-78.73 211.264-49.548 247.742 66.064 82.58 165.162 33.032 181.678 33.032 16.516 0 115.614 49.548 181.678-33.032 29.18-36.476-7.064-176.93-49.55-247.74z" fill="#FFFFFF" p-id="1146" />
      <path d="M611.098 495.484c0-45.608 36.974-82.58 82.58-82.58 49.548 0 198.194 99.098 198.194 165.162s-79.934 144.904-148.646 99.096c-49.548-33.032-132.128-148.646-132.128-181.678zM412.904 495.484c0-45.608-36.974-82.58-82.58-82.58-49.548 0-198.194 99.098-198.194 165.162s79.934 144.904 148.646 99.096c49.548-33.032 132.128-148.646 132.128-181.678z" fill="#6B676E" p-id="1147" />
      <path d="M512.002 726.622c-30.06 0-115.614 5.668-115.614 33.032 0 49.638 105.484 85.24 115.614 82.58 10.128 2.66 115.614-32.944 115.614-82.58-0.002-27.366-85.556-33.032-115.614-33.032z" fill="#464655" p-id="1148" />
      <path d="M330.324 495.484m-33.032 0a33.032 33.032 0 1 0 66.064 0 33.032 33.032 0 1 0-66.064 0Z" fill="#464655" p-id="1149" />
      <path d="M693.678 495.484m-33.032 0a33.032 33.032 0 1 0 66.064 0 33.032 33.032 0 1 0-66.064 0Z" fill="#464655" p-id="1150" />
    </svg>
  `
}

const PandaIcon = {
  template: `
    <a-icon :component="PandaSvg" />
  `,
  data() {
    return {
      PandaSvg
    }
  }
}

import { queryAllMovie } from '../../utils/api'

export default {
  name: 'tabs',
  props: {
    navList: {
      type: Array,
      default () {
        return []
      }
    }
  },
  data () {
    return {
      currentIndex: 0,
      iconList: ['smile', 'robot', 'crown', 'fork', 'fire', 'deployment-unit', 'compass', 'disconnect', 'medicine-box', 'euro', 'alert', 'database', 'customer-service', 'gift', 'thunderbolt', 'gold']
    }
  },
  components: {
    PandaIcon
  },
  mounted () {
  },
  methods: {
    switchItem ({ index, item }) {
      this.currentIndex = index
      this.$emit('switch', { item, index })
    }
  }
}
</script>
<style lang="scss" scoped>

.tabs{
  display: flex;
  width: 100%;
  height: 50px;
  margin: 0 auto;
  align-items: center;
  background: #f4f7f6;
  border-bottom: 1px solid #e8e8e8;
  border-radius: 5px;
  list-style: none;
  padding: 0;
  margin: 0;
  .switch-item{
    cursor: pointer;
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 16px;
    color: #49c5b6;
    height: 50px;
    line-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    &:before{
      content: '';
      position: absolute;
      width: 0;
      height: 2px;
      background: #1890ff;
      left: 50%;
      transform: translateX(-50%);
      bottom: 0;
      transition: width .2s linear;
    }
    &:hover{
      color: #1890ff;
    }
    &.active{
      color: #1890ff;
      &:before{
        width: 100%;
      }
    }
  }
}


.tab{
  display: flex;
  height: 44px;
  line-height: 44px;
  
  color: #000;
  .tab-item{
    flex: 1;
    text-align: center;
    position: relative;
    &:before{
      content: '';
      position: absolute;
      width: 0;
      height: 2px;
      background: #ffcd32;
      left: 50%;
      transform: translateX(-50%);
      bottom: 0;
      transition: width .2s linear;
    }
    &.router-link-active{
      .tab-link{
        color: #ffcd32
      }
      &:before{
        width: 60%
      }
    }
    .tab-link {
      padding-bottom: 5px;
      color: rgba(255, 255, 255, 0.5);
      transition: width 1s linear;
    }
  }
}
</style>
